package com.gree.changying.activity.mainactivity.framgent;


import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.gree.changying.R;
import com.gree.changying.activity.base.BasePageFragment;
import com.gree.changying.activity.mainactivity.framgent.homefrm.tuijian.adapter.RmssAdapter;
import com.gree.changying.activity.mainactivity.framgent.homefrm.tuijian.adapter.ViewPagerAdapter;
import com.gree.changying.activity.mainactivity.framgent.homefrm.tuijian.bean.Rmss;
import com.gree.changying.view.AutoViewPager;
import com.gree.changying.widget.tablayout.jtablayout.tab.Tab;
import com.gree.changying.widget.tablayout.widget.JTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MyFrm extends BasePageFragment {
    @Override
    protected void initView(View view) {
        ButterKnife.bind(this,view);
        init();
        initRmss();
    }


    /**
     * 热门赛事
     */
    @Bind(R.id.rmssTab)
    JTabLayout rmssTab;
    @Bind(R.id.rmssPager)
    AutoViewPager rmssPager;
    ViewPagerAdapter rmssAdapter;
    private void initRmss(){
        rmssAdapter = new ViewPagerAdapter();
        rmssPager.setAdapter(rmssAdapter);
        rmssPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                rmssTab.selectTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        rmssTab.addOnTabSelectedListener(new JTabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(@NonNull Tab var1) {
                rmssPager.setCurrentItem(var1.getPosition());
            }

            @Override
            public void onTabUnselected(@NonNull Tab var1) {

            }

            @Override
            public void onTabReselected(@NonNull Tab var1) {

            }
        });
        initRmssData();
    }
    private String[] rmss = {"足球","篮球"};
    private Object[][] rmssList = {
            {"土超","02-20 18:30","利物浦","切尔西",43},
            {"土超","02-20 18:30","利物浦","切尔西",32},
            {"土超","02-20 18:30","利物浦","切尔西",64},
            {"土超","02-20 18:30","利物浦","切尔西",34},
            {"土超","02-20 18:30","利物浦","切尔西",63},
            {"土超","02-20 18:30","利物浦","切尔西",74},
            {"土超","02-20 18:30","利物浦","切尔西",745},
            {"土超","02-20 18:30","利物浦","切尔西",85},
            {"土超","02-20 18:30","利物浦","切尔西",576},
            {"土超","02-20 18:30","利物浦","切尔西",45},
    };
    private List<Rmss> getRmss(){
        List<Rmss> rmsses = new ArrayList<>();
        for(Object[] o:rmssList){
            Rmss rmss = new Rmss();
            rmss.setTag((String)o[0]);
            rmss.setTime((String)o[1]);
            rmss.setName1((String)o[2]);
            rmss.setName2((String)o[3]);
            rmss.setFanan((int)o[4]);
            rmsses.add(rmss);
        }
        return rmsses;
    }
    private void initRmssData(){
        List<View> views = new ArrayList<>();
        for(String s:rmss){
            Tab tab = rmssTab.newTab().setTitle(s);
            tab.setTitleColor(getResources().getColor(R.color.tabDefaultColor)
                    ,getResources().getColor(R.color.white));
            rmssTab.addTab(tab);
            View tView =  LayoutInflater.from(mContext).inflate(R.layout.pager_recycleview, null);
            RecyclerView rv = tView.findViewById(R.id.rv);
            rv.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false) {
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
            //rv.setHasFixedSize(true);
            RmssAdapter rmssAdapter = new RmssAdapter(R.layout.item_tuijian_rmss,getRmss());
            rv.setAdapter(rmssAdapter);
            views.add(tView);
        }
        rmssAdapter.update(views);
        rmssPager.setCurrentItem(0);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.frm_my;
    }

    private void init(){

    }
}
